home *** CD-ROM | disk | FTP | other *** search
Wrap
Professional Page Document | 1991-06-12 | 24.2 KB | 216 lines
Professional Page V1.2 dPENV Helvetica Bookman Courier zapfdingbats helvetican >Green ~Blue Yellow Magenta >Cyan '(PDOC timerIX37.ppg TAdam Levin Disabling Sprite DMA from a Vertical Blank Interrupt HuPBOX LdPTXT Z\n\B\ff<Courier>\fs<7>\jf\lr<105>\ls<0.000>\ps<100>\t<0>\c<Black>U259 U260 U261 U262\. h#PBOX j,PBOX W\n\ff<helvetican>\fs<10>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Socketed Chip RAM\. KPBOX X\n\ff<helvetican>\fs<10>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Soldered Chip\MRAM\. Z\n\B\ff<Courier>\fs<7>\jf\lr<105>\ls<0.000>\ps<100>\t<0>\c<Black>U263 U264 U265 U266\. Z\n\B\ff<Courier>\fs<7>\jf\lr<105>\ls<0.000>\ps<100>\t<0>\c<Black>U271 U272 U273 U274\. y\n\B\ff<Courier>\fs<7>\jf\lr<105>\ls<0.000>\ps<100>\t<0>\c<Black> U267 U268 U269 U270\. PPAG jPSGR Black Black ePBOX (PBOX l\n\B\ff<Helvetica>\fs<10>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Timers, Serial Port and Parallel Port\. -_PBOX V\n\B\ff<Helvetica>\fs<10>\jc\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Page IX - 38\. KQPBOX s\n\B\ff<Helvetica>\fs<10>\jr\lr<125>\ls<0.000>\ps<100>\t<0>\c<Black>Stopwatch Functions With the timer.device\. xbPBOX `\n\B\I\O\ff<Helvetica>\fs<30>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Amiga Mail\ff<Times> /PBOX Black Black oPBOX OPBOX Black Black p\n\B\ff<Helvetica>\fs<10>\lr<125>\ls<0.000>\ps<100>\t<0>\c<Black>Stopwatch Functions With the timer.device\. V\n\B\ff<Helvetica>\fs<10>\jc\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Page IX - 39\. 1PBOX o\n\B\ff<Helvetica>\fs<10>\jr\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Timers, Serial Port and Parallel Port\. <PTXT V\n\B\I\O\ff<Helvetica>\fs<30>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Amiga Mail * PBOX Black Black .rPPAG .`PBOX .WPTXT \n\B\ff<Times>\fs<30>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black> Stopwatch Functions with the timer.device\fs<14> by Mike Sinz \fs<12>\lr<125>To measure time on the Amiga the system software provides the \Itimer.device.\i The \Itimer.device\i is very handy for many purposes, however, it does not have a built-in stopwatch. It does have some time manipulation functions that make this a simple thing to do though. This article shows how to do stopwatch functions using the \Itimer.device.\i The example code contains four routines needed to set up and use the stopwatch. The routines are: \ff<zapfdingbats>\fs<10>o\ff<Times>\s\ff<Courier>struct timerequest *Init_Timer (VOID)\ff<Times> \ff<zapfdingbats>o\ff<Times>\s\ff<Courier>VOID \sTimer_Start (struct timerequest *)\ff<Times> \ff<zapfdingbats>o\ff<Times>\s\ff<Courier>VOID \sTimer_Stop (struct timerequest *)\ff<Times> \ff<zapfdingbats>o\ff<Times>\s\ff<Courier>VOID \sFree_Timer (struct timerequest *)\ff<Times>\fs<12> The stopwatch functions all use a struct timerequest as their main parameter. This is just the usual Amiga IORequest structure with two extra fields for seconds and microseconds. Init_Timer() sets up the \Itimer.device\i and returns a pointer to a struct timerequest. This pointer is used in Timer_Start() and Timer_Stop() which measure the elapsed time. Finally, Free_Timer() is used to close the \Itimer.device\i and free the memory used for the timerequest. An example main() function is listed below to show how to use the stopwatch functions to measure elapsed time. The example just does a Delay(73L) and then displays the amount of time that took. Some uses for the program might include measuring how long a student takes to answer a question, the amount of time a player has been playing, or how fast the system is. For more information on the \Itimer.device,\i refer to the\I ROM Kernel Manual: Libraries and Devices\i (p. 871, ISBN 0-201-18187-8).\. kPBOX LPSGR Black Black gPBOX p\n\B\ff<Helvetica>\fs<10>\lr<125>\ls<0.000>\ps<100>\t<0>\c<Black>Stopwatch Functions with the timer.device\. V\n\B\ff<Helvetica>\fs<10>\jc\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Page IX - 37\. o\n\B\ff<Helvetica>\fs<10>\jr\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Timers, Serial Port and Parallel Port\. WnPBOX `\n\B\I\O\ff<Helvetica>\fs<30>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Amiga Mail\ff<Times> Black Black P\n\I\ff<Times>\fs<12>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>May/June 1990\. [PSGR Black Black 7PBOX \n\ff<Courier>\fs<9>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>/* \s* Example stopwatch functions using the Amiga timer.device... \s*/ \s* Makefile used to compile with Lattice C 5.04 or 5.05 # MakeFile for StopWatch CFLAGS= -b1 -cfirstq -ms0 -rr1 -v -w OBJS= StopWatch.o LIBS= LIB:lcsr.lib .c.o: @LC $(CFLAGS) $* StopWatch: $(OBJS) @BLink FROM LIB:c.o $(OBJS) TO StopWatch LIB $(LIBS) SMALLDATA SMALLCODE #include <exec/types.h> #include <exec/memory.h> #include <devices/timer.h> #include <proto/exec.h> #include <proto/timer.h> #include <proto/dos.h> #include <stdio.h> \s* The library base for the timer... struct Library *TimerBase=NULL; \s* This gets the starting time... VOID Timer_Start(struct timerequest *Time_Req) \s Time_Req->tr_node.io_Command=TR_GETSYSTIME; \s Time_Req->tr_node.io_Flags=IOF_QUICK; \s DoIO((struct IORequest *)Time_Req); \s* This gets the ending time and computes the time difference \s* in the timerequest->tr_time. VOID Timer_Stop(struct timerequest *Time_Req) struct timeval StartTime; \s StartTime=Time_Req->tr_time; \s Time_Req->tr_node.io_Command=TR_GETSYSTIME; \s Time_Req->tr_node.io_Flags=IOF_QUICK; \s DoIO((struct IORequest *)Time_Req); \s SubTime(&(Time_Req->tr_time),&StartTime); \s* Initialize the stopwatch... struct timerequest *Init_Timer(VOID) register struct timerequest *Time_Req=NULL; register struct MsgPort *port=NULL; \s if (port=CreatePort(NULL,NULL)) \s { \s if (Time_Req=(struct timerequest *)CreateExtIO(port, \s sizeof(struct timerequest))) \s { \s if (!OpenDevice(TIMERNAME,UNIT_VBLANK, \s (struct IORequest *)Time_Req,NULL)) \s { \s TimerBase=(struct Library *)Time_Req->tr_node.io_Device; \s } \s else \s { \s DeleteExtIO((struct IORequest *)Time_Req); \s Time_Req=NULL; \s } \s } \s if (!Time_Req) \s { \s DeletePort(port); \s port=NULL; \s } \s } \s return(Time_Req); \s* Free up the timer... VOID Free_Timer(struct timerequest *Time_Req) \s if (Time_Req) \s { \s CloseDevice((struct IORequest *)Time_Req); \s DeletePort(Time_Req->tr_node.io_Message.mn_ReplyPort); \s DeleteExtIO((struct IORequest *)Time_Req); \s } \s* A simple main() to use these features... VOID main(int argc, char *argv[]) register struct timerequest *StopWatch; \s if (argc) /* Check if CLI... */ \s { \s if (StopWatch=Init_Timer()) \s { \s Timer_Start(StopWatch); \s /* Now we do something... */ \s Delay(73L); \s Timer_Stop(StopWatch); \s /* Now we display the results... */ \s printf("Time taken: %ld.%06ld seconds\\n", \s StopWatch->tr_time.tv_secs, \s StopWatch->tr_time.tv_micro); \s /* Free the structure again... */ \s Free_Timer(StopWatch); \s } \s } \B\I\O\ff<Bookman>\fs<14>A\. ]wPTXT l\n\B\ff<Helvetica>\fs<10>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Timers, Serial Port and Parallel Port\. WPBOX =PTXT V\n\B\ff<Helvetica>\fs<10>\jc\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Page IX - 38\. s\n\B\ff<Helvetica>\fs<10>\jr\lr<125>\ls<0.000>\ps<100>\t<0>\c<Black>Stopwatch Functions with the timer.device\. "PTXT `\n\B\I\O\ff<Helvetica>\fs<30>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Amiga Mail\ff<Times> GPBOX ,PSGR Black Black uPSGR Black Black p\n\B\ff<Helvetica>\fs<10>\lr<125>\ls<0.000>\ps<100>\t<0>\c<Black>Stopwatch Functions with the timer.device\. V\n\B\ff<Helvetica>\fs<10>\jc\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Page IX - 39\. o\n\B\ff<Helvetica>\fs<10>\jr\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Timers, Serial Port and Parallel Port\. l^PTXT V\n\B\I\O\ff<Helvetica>\fs<30>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Amiga Mail NPSGR Black Black ]PBOX Black Black sPBOX qPBOX l\n\B\ff<Helvetica>\fs<10>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Timers, Serial Port and Parallel Port\. V\n\B\ff<Helvetica>\fs<10>\jc\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Page IX - 40\. s\n\B\ff<Helvetica>\fs<10>\jr\lr<125>\ls<0.000>\ps<100>\t<0>\c<Black>Stopwatch Functions with the timer.device\. lPBOX JPTXT `\n\B\I\O\ff<Helvetica>\fs<30>\lr<120>\ls<0.000>\ps<100>\t<0>\c<Black>Amiga Mail\ff<Times> %vPSGR Black Black